﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using OpenSoftStore.BusinessLogic.Admin;
using OpenSoftStore.BusinessLogic.Bill;
using OpenSoftStore.BusinessLogic.Common;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.BusinessLogic.Product;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Client.UIL.ManageCommon;
using OpenSoftStore.Client.UIL.ManageMember.Info;
using OpenSoftStore.Orm.Model;
using OpenSoftStore.Orm.Static;
using OpenSoftStore.Orm.View;
using OpenSoftStore.Orm.Logic;

namespace OpenSoftStore.Client.UIL.ManageBilling
{
    public partial class BillAdd : UserControl
    {
        public T_Bill Tbill;
        public V_Bill Vbill;
        public V_Member Vmember;
        public MemberLogic LgcMember;
        public BillLogic LgcBill;
        public TreeLogic LgcTree;
        public ProductLogic LgcProduct;
        public List<T_BillItem> BillItems;
        public ComboLogic LgcCombo;
        public AdminLogic LgcAdmin;
        public DinnerSaleLogic LgcDinnerSale;
        public T_MemberTree TmemberTree;
        public List<T_MemberTreeDinner> TmemberTreeDinners;
        public Boolean Drog = false;
        public int Top = 0;
        public int Left = 0;


        public BillAdd()
        {
            InitializeComponent();
            Tbill = new T_Bill();
            Vmember = new V_Member();
            LgcMember = new MemberLogic();
            LgcBill = new BillLogic();
            LgcTree = new TreeLogic();
            LgcProduct = new ProductLogic();
            BillItems = new List<T_BillItem>();
            LgcCombo = new ComboLogic();
            LgcAdmin = new AdminLogic();
            Vbill = new V_Bill();
            TmemberTree=new T_MemberTree();
            TmemberTreeDinners=new List<T_MemberTreeDinner>();
            LgcDinnerSale = new DinnerSaleLogic();


            SPACommon.SetDataGridStyle(grdProduct);
            SPACommon.SetDataGridStyle(grdBillItem);
            SPACommon.SetDataGridStyle(dgvDinnerSale);
            SPACommon.SetDataGridStyle(dgvDinnerSaleItem);
        }

        private void BillAdd_Load(object sender, EventArgs e)
        {
            var stores = LgcCombo.GetComboByBuzType("Pos", "b0def1a7-bf25-45f2-b65a-6dc586dbfc2c").ToList();
            dgvCmbStore.DataSource = stores;
            dgvCmbStore.DisplayMember = "DisplayText";
            dgvCmbStore.ValueMember = "Value1";
            if (stores.Any())
                dgvCmbStore.DefaultCellStyle.NullValue = stores[0].DisplayText;
       

            txtProductSearch.Focus();
            var tree = LgcTree.GetTreeFirstByType("BillTree");
            txtTreeId.Text = tree.Name;
            Tbill.TreeId = tree.Id;

            var admins = LgcAdmin.GetAdminView().ToList();
            cmbAdmin.DataSource = LgcAdmin.GetAdminView().ToList();
            cmbAdmin.DisplayMember = "Name";
            cmbAdmin.ValueMember = "Id";
            cmbAdmin.Text = S_Admin.Name;

            dgvCmbAdmin.DataSource = admins;
            dgvCmbAdmin.DisplayMember = "Name";
            dgvCmbAdmin.ValueMember = "Id";
            if (admins.Any())
                dgvCmbAdmin.DefaultCellStyle.NullValue = admins[0].Name;

            grdProduct.AutoGenerateColumns = false;
            grdProduct.DataSource = LgcProduct.GetProdutView();
            grdBillItem.AutoGenerateColumns = false;

            var brokerageTypes = LgcCombo.GetComboByBuzType("BrokerageType").ToList();
            dgvCmbBorakerageType.DataSource = brokerageTypes;
            dgvCmbBorakerageType.DisplayMember = "DisplayText";
            dgvCmbBorakerageType.ValueMember = "Value1";
            if (brokerageTypes.Any())
                dgvCmbBorakerageType.DefaultCellStyle.NullValue = brokerageTypes[0].DisplayText;

            lblProduct.Text = grdProduct.RowCount.ToString();
            lblBillItem.Text = grdBillItem.RowCount.ToString();
        }

        public void GetMember(string id)
        {
            Vmember = LgcMember.GetMemberViewObject("where T_Member.Id= '" + id + "'");
            TmemberTree = LgcMember.Where<T_MemberTree>(m => m.TreeId == Vmember.TreeId).FirstOrDefault();
            TmemberTreeDinners = LgcMember.GetMemberTreeDinnerView(" where T_MemberTree.TreeId='" + Vmember.TreeId + "'").ToList();
            if (TmemberTreeDinners == null) 
                TmemberTreeDinners = new List<T_MemberTreeDinner>();
            if (TmemberTree == null)
                TmemberTree=new T_MemberTree {Discount = 1};
            txtDiscount.Text = TmemberTree.Discount.ToString();
            Tbill.BillNo = LgcBill.GetCountNo("T_Bill", true);
            UiSetValue(Vmember, Tbill);
            Tbill.MemberId = Vmember.Id;
            Tbill.ShopId = S_Admin.ShopId;

            if (Vmember.Name != "临时客户") dtAddTime.Enabled = false;

            dgvDinnerSale.AutoGenerateColumns = false;
            var data = LgcDinnerSale.GetDinnerSalesView(" where t1.MemberId ='" + Vmember.Id + "'");
            dgvDinnerSale.DataSource = data;
            var dinnerSaleId = "";
            if (data.Any()) dinnerSaleId = data.FirstOrDefault().Id;
            dgvDinnerSaleItem.AutoGenerateColumns = false;
            dgvDinnerSaleItem.DataSource = LgcDinnerSale.GetDinnerSaleItemsView(" where T_DinnerSaleItem.DinnerSaleId = '" + dinnerSaleId + "'");
        }

        public void GetBill(string id)
        {
            Vbill = LgcBill.GetBillViewObject(" where T_Bill.Id= '" + id + "'");
            txtCardId.Text = Vbill.CardId;
            txtTreeName.Text = Vbill.TreeName;
            txtName.Text = Vbill.MemberName;
            txtTelNum.Text = Vbill.TelNum;
            txtOwedMoney.Text = Vbill.OwedMoney.ToString();
            txtHaveValue.Text = Vbill.HaveValue.ToString();
            txtMark.Text = Vbill.Mark.ToString();
            txtBillNo.Text = Vbill.BillNo;
            dtPayTime.Value = Vbill.PayTime;
            dtAddTime.Value = Vbill.AddTime;
            Tbill = LgcBill.GetBill(" Id= '" + id + "'");
            BillItems = LgcBill.GetBillItems(" BillId= '" + id + "'");
            if (Tbill.State == "已经结算" || Tbill.State == "已结算")
            {
                lblPaied.Visible = true;
                //this.Enabled = false;
                this.PnlControlArea.Enabled = false;
                this.PnlFooter.Enabled = false;
                lblPayTime.Visible = true;
                dtPayTime.Visible = true;
            }
            grdBillItem.AutoGenerateColumns = false;
            grdBillItem.DataSource = null;
            grdBillItem.DataSource = BillItems;
            lblTotalMoney.Text = BillItems.Where(m => m.IsGift != "是").Sum(m => m.Price * m.Amount * m.Discount).ToString();
        }

        private void UiSetValue(V_Member vMember, T_Bill tBill)
        {
            txtCardId.Text = vMember.CardId;
            txtTreeName.Text = vMember.TreeName;
            txtName.Text = vMember.Name;
            txtTelNum.Text = vMember.TelNum;
            txtOwedMoney.Text = vMember.OwedMoney.ToString();
            txtHaveValue.Text = vMember.HaveValue.ToString();
            txtMark.Text = vMember.Mark.ToString();
            txtBillNo.Text = tBill.BillNo;
        }

        private void trTree_Click(object sender, EventArgs e)
        {
            var formTreeSelecter = new FormTreeSelecter();
            formTreeSelecter.GetTreeByType("BillTree");
            formTreeSelecter.ShowDialog();
            if (formTreeSelecter.DialogResult != DialogResult.OK) return;
            Tbill.TreeId = formTreeSelecter.TypeId;
            txtTreeId.Text = formTreeSelecter.TypeText;
        }

        private void button12_Click(object sender, EventArgs e)
        {
            var id = grdProduct.CurrentRow.Cells["Id"].Value.ToString();
            var name = grdProduct.CurrentRow.Cells["ProductName"].Value.ToString();
            var treeName = grdProduct.CurrentRow.Cells["treeName"].Value.ToString();
            var salePrice = Convert.ToDecimal(grdProduct.CurrentRow.Cells["salePrice"].Value);

            BillItems.Add(new T_BillItem
            {
                Id = id,
                ItemName = name,
                Type = treeName,
                Price = salePrice,
                Amount = Convert.ToDecimal(1.00),
                Discount = Convert.ToDecimal(1.00)
            });
            grdBillItem.DataSource = null;
            grdBillItem.DataSource = BillItems;
        }

        private void button10_Click(object sender, EventArgs e)
        {

            var name = grdBillItem.CurrentRow.Cells["ItemName"].Value.ToString();
            grdBillItem.DataSource = null;
            var product = BillItems.First(m => m.ItemName == name);
            BillItems.Remove(product);
            //grdBillItem.CurrentRow
            grdBillItem.DataSource = BillItems;
            //grdBillItem.Rows.Remove(grdBillItem.CurrentRow);

        }

        private void txtProductSearch_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void btnAddItem_Click(object sender, EventArgs e)
        {
            if (grdProduct.CurrentRow == null) return;
            var id = grdProduct.CurrentRow.Cells["Id"].Value.ToString();
            var name = grdProduct.CurrentRow.Cells["ProductName"].Value.ToString();
            var treeName = grdProduct.CurrentRow.Cells["treeName"].Value.ToString();
            var salePrice = Convert.ToDecimal(grdProduct.CurrentRow.Cells["salePrice"].Value);
            var allStore = Convert.ToDecimal(grdProduct.CurrentRow.Cells["AllStore"].Value);
            var isProject = grdProduct.CurrentRow.Cells["IsProject"].Value.ToString();
            var brokerageType = grdProduct.CurrentRow.Cells["BrokerageType"].Value.ToString();
            var brokerageNum = Convert.ToDecimal(grdProduct.CurrentRow.Cells["BrokerageNum"].Value);

            //if (allStore <= 0) return;
            decimal discount=1;
            if (TmemberTreeDinners.Any(m => m.ProductId == id))
            {
                discount = TmemberTree.Discount;
            }
            string pos = ((T_Combo)dgvCmbStore.Items[0]).Value1;
            string adminId = ((V_Admin)dgvCmbAdmin.Items[0]).Id;
            if (BillItems == null) BillItems = new List<T_BillItem>();
            BillItems.Add(new T_BillItem
            {
                Id = id,
                ProductId = id,
                ItemName = name,
                Type = treeName,
                Price = salePrice,
                Amount = Convert.ToDecimal(1.00),
                Discount = discount,
                IsProject = isProject,
                Pos = pos,
                AdminId = adminId,
                BorakerageType = brokerageType,
                BorakerageNum = brokerageNum
                //BorakerageType = dgvCmbBorakerageType.d
            });
            grdBillItem.DataSource = null;
            grdBillItem.DataSource = BillItems;
            lblBillItem.Text = grdBillItem.RowCount.ToString();
            if (grdBillItem.RowCount > 0) grdBillItem.CurrentCell = grdBillItem.Rows[grdBillItem.RowCount - 1].Cells[0];
            //grdBillItem.se
            lblTotalMoney.Text = BillItems.Where(m => m.IsGift != "是").Sum(m => m.Price * m.Amount * m.Discount).ToString();
        }

        private void btnDeleteItem_Click(object sender, EventArgs e)
        {
            if (grdBillItem.CurrentRow == null) return;
            var name = grdBillItem.CurrentRow.Cells["ItemName"].Value.ToString();
            grdBillItem.DataSource = null;
            var product = BillItems.First(m => m.ItemName == name);
            BillItems.Remove(product);
            //grdBillItem.CurrentRow
            grdBillItem.DataSource = BillItems;
            lblBillItem.Text = grdBillItem.RowCount.ToString();
            if (grdBillItem.RowCount > 0) grdBillItem.CurrentCell = grdBillItem.Rows[grdBillItem.RowCount - 1].Cells[0];
            //grdBillItem.Rows.Remove(grdBillItem.CurrentRow);
            lblTotalMoney.Text = BillItems.Where(m => m.IsGift != "是").Sum(m => m.Price * m.Amount * m.Discount).ToString();
        }

        private void txtProductSearch_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void txtProductSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
            {
                if (grdProduct.RowCount == 0) return;
                int index, move = 1;
                if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) move = -1;
                if (grdProduct.CurrentRow == null) index = 0;
                else if (grdProduct.CurrentRow.Index + move >= grdProduct.RowCount || grdProduct.CurrentRow.Index + move < 0)
                    index = 0;
                else index = grdProduct.CurrentRow.Index + move;
                if ((e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) && index == 0) index = 0;
                grdProduct.Rows[index].Selected = true; //选中结果所在的行
                grdProduct.CurrentCell = grdProduct.Rows[index].Cells[0];
                return;
            }

            if (e.KeyCode == Keys.Add || e.KeyCode == Keys.Enter)
            {
                if (rdBarCode.Checked)
                {
                    var barCode = txtProductSearch.Text;
                    grdProduct.AutoGenerateColumns = false;
                    grdProduct.DataSource = null;
                    string whereBarCode = string.Format(" where E.BarCode like '%{0}%' ", barCode);
                    grdProduct.DataSource = LgcProduct.GetProdutView(whereBarCode);
                }
                btnAddItem_Click(null, null);
                if (txtProductSearch.Text.Length > 0) txtProductSearch.Text = txtProductSearch.Text.Substring(0, txtProductSearch.Text.Length - 1);
                txtProductSearch.Text = "";
                txtProductSearch.Focus();
                return;
            }
            if (e.KeyCode == Keys.Subtract)
            {
                btnDeleteItem_Click(null, null);
                if (txtProductSearch.Text.Length > 0) txtProductSearch.Text = txtProductSearch.Text.Substring(0, txtProductSearch.Text.Length - 1);
                return;
            }
            var search = txtProductSearch.Text;
            grdProduct.AutoGenerateColumns = false;
            grdProduct.DataSource = null;

            string where =
                string.Format(" where p.Name like '%{0}%' or p.ProductNo like '%{0}%' or p.ShortName like '%{0}%' or p.Model like '%{0}%' or E.BarCode like '%{0}%'",
               search);
            grdProduct.DataSource = LgcProduct.GetProdutView(where);
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            int row = LgcBill.Save(Tbill, BillItems);
            string message = "";
            message = row == 0 ? "保存失败" : "保存成功";
            FormSysMessage.ShowSuccessMsg(message);
        }

        private void txtRemark_Leave(object sender, EventArgs e)
        {
            txtProductSearch.Focus();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (BillItems.Count == 0) return;
            Tbill.Remark = txtRemark.Text.Trim();
            grdBillItem.EndEdit(DataGridViewDataErrorContexts.Commit);
            Tbill.AdminId = cmbAdmin.SelectedValue.ToString();
            int row = LgcBill.Save(Tbill, BillItems);
            const string message = "保存失败";
            if (row == 0)
            {
                FormSysMessage.ShowSuccessMsg(message);
                return;
            }

            BillList.Instance.btnSearch_Click(null, null);
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.DialogResult = DialogResult.Cancel;
            findForm.Close();
        }

        private void btnPay_Click(object sender, EventArgs e)
        {
            if (BillItems.Count == 0) return;
            grdBillItem.EndEdit(DataGridViewDataErrorContexts.Commit);
            Tbill.AdminId = cmbAdmin.SelectedValue.ToString();
            int row = LgcBill.Save(Tbill, BillItems);
            const string message = "保存失败";
            if (row == 0) FormSysMessage.ShowSuccessMsg(message);
            var billPay = new BillPayWindow();
            billPay.GetBill(Tbill.Id);
            billPay.ShowDialog();
            if (billPay.DialogResult != DialogResult.OK) return;
            BillList.Instance.btnSearch_Click(null, null);

            var findForm = FindForm();
            if (findForm == null) return;
            findForm.DialogResult = DialogResult.OK;
            findForm.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.DialogResult = DialogResult.Cancel;
            findForm.Close();
        }

        private void grdBillItem_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            grdBillItem.EndEdit(DataGridViewDataErrorContexts.Commit);
            lblTotalMoney.Text = BillItems.Where(m => m.IsGift != "是").Sum(m => m.Price * m.Amount * m.Discount).ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("a");
        }

        private void pbClose_Click(object sender, EventArgs e)
        {
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.DialogResult = DialogResult.Cancel;
            findForm.Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            pnlDinnerSelect.Top = grpBillItem.Top - pnlDinnerSelect.Height + 40;
            pnlDinnerSelect.Left = grpBillItem.Left;
            pnlDinnerSelect.Show();
        }

        private void pctDinnerClose_Click(object sender, EventArgs e)
        {
            pnlDinnerSelect.Hide();
        }

        private void dgvDinnerSale_SelectionChanged(object sender, EventArgs e)
        {
            dgvDinnerSaleItem.AutoGenerateColumns = false;
            var id = dgvDinnerSale.CurrentRow.Cells["DinnerSaleId"].Value.ToString();
            dgvDinnerSaleItem.DataSource = null;
            dgvDinnerSaleItem.DataSource = LgcDinnerSale.GetDinnerSaleItemsView(" where T_DinnerSaleItem.DinnerSaleId = '" + id + "'");
        }

        private void dgvDinnerSaleItem_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //var dinnerType="";
            //if (dgvDinnerSaleItem.CurrentRow == null) return;
            //var id = dgvDinnerSaleItem.CurrentRow.Cells["DinnerObjectId"].Value.ToString();
            //var name = dgvDinnerSaleItem.CurrentRow.Cells["DinnerItemName"].Value.ToString();
            //if (dgvDinnerSaleItem.CurrentRow.Cells["DinnerType"].Value != null)
            //    dinnerType = dgvDinnerSaleItem.CurrentRow.Cells["DinnerType"].Value.ToString();
            //var treeName = dgvDinnerSaleItem.CurrentRow.Cells["DinnerTreeName"].Value.ToString();
            //var salePrice = Convert.ToDecimal(dgvDinnerSaleItem.CurrentRow.Cells["DinnerSalePrice"].Value);
            //if (dinnerType == "")
            //{
            //}
            //BillItems.Add(new T_BillItem
            //{
            //    Id = id,
            //    ProductId = id,
            //    ItemName = name,
            //    Type = treeName,
            //    Price = salePrice,
            //    Amount = Convert.ToDecimal(1.00),
            //    Discount = Convert.ToDecimal(1.00)
            //});
            //grdBillItem.DataSource = null;
            //grdBillItem.DataSource = BillItems;
            //lblTotalMoney.Text = BillItems.Sum(m => m.Price * m.Amount).ToString();
        }

        private void dgvDinnerSaleItem_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvDinnerSale_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvDinnerSale_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvDinnerSale.CurrentRow == null) return;
            var dinnerId = dgvDinnerSale.CurrentRow.Cells["DinnerId"].Value.ToString();
            var dinnerSaleId = dgvDinnerSale.CurrentRow.Cells["DinnerSaleId"].Value.ToString();
            var times = dgvDinnerSale.CurrentRow.Cells["Times"].Value.ToString();
            if (times == "0") return;

            string pos = ((T_Combo)dgvCmbStore.Items[0]).Value1;
            string adminId = ((V_Admin)dgvCmbAdmin.Items[0]).Id;
            if (BillItems.Any(m => m.DinnerSaleId == dinnerSaleId)) return;
            for (int i = 0; i < dgvDinnerSaleItem.RowCount; i++)
            {
                var dinnerType = "";
                var dinnerObjectId = dgvDinnerSaleItem.Rows[i].Cells["DinnerObjectId"].Value.ToString();
                var dinnerSaleItemId = dgvDinnerSaleItem.Rows[i].Cells["DinnerSaleItemId"].Value.ToString();
                var name = dgvDinnerSaleItem.Rows[i].Cells["DinnerItemName"].Value.ToString();
                if (dgvDinnerSaleItem.Rows[i].Cells["DinnerType"].Value != null)
                    dinnerType = dgvDinnerSaleItem.Rows[i].Cells["DinnerType"].Value.ToString();
                var treeName = dgvDinnerSaleItem.Rows[i].Cells["DinnerTreeName"].Value.ToString();
                var LowestPrice = Convert.ToDecimal(dgvDinnerSaleItem.Rows[i].Cells["LowestPrice"].Value);

                V_Product product = LgcProduct.GetProdutView(" where P.Id ='" + dinnerObjectId + "'").FirstOrDefault();
                if (product == null) continue;

                decimal discount = 1;
                if (TmemberTreeDinners.Any(m => m.ProductId == dinnerObjectId))
                {
                    discount = TmemberTree.Discount;
                }

                if (dinnerType == "")
                {
                }
                BillItems.Add(new T_BillItem
                {
                    //Id = id,
                    ProductId = dinnerObjectId,
                    ItemName = product.Name,
                    Type = product.TreeName,
                    Price = product.SalePrice,
                    DinnerSaleItemPrice = LowestPrice,
                    Amount = Convert.ToDecimal(1.00),
                    Discount = discount,
                    DinnerSaleId = dinnerSaleId,
                    DinnerSaleItemId = dinnerSaleItemId,
                    DinnerId = dinnerId,
                    Pos = pos,
                    AdminId = adminId,
                    BorakerageType = product.BrokerageType,
                    BorakerageNum = product.BrokerageNum
                });
                grdBillItem.DataSource = null;
                grdBillItem.DataSource = BillItems;
                lblTotalMoney.Text = BillItems.Sum(m => m.Price * m.Price * m.Amount).ToString();

            }

        }

        private void dgvDinnerSale_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void grdBillItem_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            grdBillItem.EndEdit(DataGridViewDataErrorContexts.Commit);
            if (grdBillItem.CurrentRow == null) return;
            int row = grdBillItem.CurrentRow.Index;
            //var name = grdBillItem.CurrentRow.Cells["ItemName"].Value.ToString();
            grdBillItem.DataSource = null;
            var product = BillItems[row];
            if (product.IsGift == "是")
            {
                product.Price = 0;
            }
            //BillItems.Remove(product);
            //grdBillItem.CurrentRow
            grdBillItem.DataSource = BillItems;
            //lblBillItem.Text = grdBillItem.RowCount.ToString();
            //if (grdBillItem.RowCount > 0) grdBillItem.CurrentCell = grdBillItem.Rows[grdBillItem.RowCount - 1].Cells[0];
            //grdBillItem.Rows.Remove(grdBillItem.CurrentRow);
            lblTotalMoney.Text = BillItems.Where(m => m.IsGift != "是").Sum(m => m.Price * m.Amount * m.Discount).ToString();
        }

        private void lnkMember_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var id = Vmember.Id;
            var name = Vmember.Name;
            var cardId = Vmember.CardId;
            var member = new T_Member { Id = id, Name = Name, CardId = cardId };
            var window = new MemberInfoEditWindow();
            window.SetMember(member);
            window.ShowDialog();
        }

        private void PnlInfoTitle_MouseDown(object sender, MouseEventArgs e)
        {
            Drog = true;
            Top = e.Y;
            Left = e.X;
        }

        private void PnlInfoTitle_MouseMove(object sender, MouseEventArgs e)
        {
            if (!Drog) return;
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.Top += e.Y - Top;
            findForm.Left += e.X - Left;
        }

        private void PnlInfoTitle_MouseUp(object sender, MouseEventArgs e)
        {
            Drog = false;
        }
    }
}
